package com.byq.mm.abstractx.cluster.client;

import com.byq.mm.abstractx.device.Device;
import com.byq.mm.abstractx.engine.CoreEnvironment;
import com.byq.mm.abstractx.protocol.Interaction;

abstract public class ClusterClient{
	String cluster;
	Device device;
	protected CoreEnvironment env;
	public String getCluster() {
		return cluster;
	}
	public Device getDevice() {
		return device;
	}
	public ClusterClient(String cluster, Device device, CoreEnvironment e) {

		this.cluster = cluster;
		this.device = device;
		this.env = e;
	}

	abstract public boolean onReport(Interaction i);

	protected Interaction createRequest() {
		Interaction i = new Interaction();
		i.direction = Interaction.DIRECTION_FROM_CLIENT;
		i.cluster = getCluster();
		i.from = this.env.getServerDeviceManager().getLocalServerDevice()
				.getId();
		i.to = this.getDevice().getId();
		return i;
	}

	protected void command(String command) {
		Interaction i = this.createRequest();
		i.command = command;
		env.getExtensionManager().sendInteraction(i,
				getDevice().getTransportId());
	}
}
